#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;

const int N = 200010;

int q[N];
int w[N];
int f[N];
int n, m;

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)   scanf("%d", &w[i]);

    int hh = 0, tt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (q[hh] + m < i)   hh++;

        f[i] = f[q[hh]] + w[i];
        while (hh <= tt && f[q[tt]] >= f[i]) tt--;
        q[++tt] = i;
    }

    int res = 1e9;
    for (int i = n; i >= n - m + 1; i--)   res = min(res, f[i]);

    printf("%d\n", res);
    return 0;
}